package cn.doitedu.javase.io;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @Author: 深似海
 * @Site: <a href="www.51doit.com">多易教育</a>
 * @QQ: 657270652
 * @Date: 2024/2/1
 * @Desc: 学大数据，上多易教育
 *   FileReader  / FileWriter
 **/
public class _05_FileWriter和FileReader基本Api示例 {
    public static void main(String[] args) throws IOException {


        FileWriter fileWriter = new FileWriter("e:/c.txt", false);

        fileWriter.write("我爱,多易\n");
        fileWriter.write("我就在多易doe学习");
        String encoding = fileWriter.getEncoding();
        System.out.println(encoding);
        fileWriter.close();


        // ---------------------

        // 1. 构造reader
        FileReader fileReader = new FileReader("e:/c.txt");
        char[] chars = new char[10];
        int read;
        // 2. 读数据
        while( (read = fileReader.read(chars))!=-1 ){
            System.out.print(new String(chars,0,read));
        }

        // 3.关流
        fileReader.close();
    }

}
